
cmake_minimum_required(VERSION 3.5.1)

project(z-tools-toolbox LANGUAGES CXX VERSION 1.2.0)

# +---------------------------------+
# |      CMake Build Module         |
# +---------------------------------+
include(cmake/SparkWithGit.cmake)

spark_initialize_modules()

# +---------------------------------+
# |      CMake Build Step           |
# +---------------------------------+
configure_file(cmake/config.h.in config.h)

# 资源文件路径
set(QRC_SOURCES "resources.qrc")
include_directories(plugins/include)
spark_file_glob(BUILTIN_SOURCES
    plugins/include/*.h
)

spark_file_glob(WIDGETS_SOURCES
    src/ui/widgets/animationicon/*.*
    src/ui/widgets/animationtext/*.*
)

spark_add_library_realpaths(
    src/ui/widgets/windowpos
)
spark_framework_include_with_git(windowpos
    https://gitee.com/spark-framework-libs/spark-framework-features
    FEATURES screenutil)

set(EXTENSTIONS_DIR plugins)
# 引入 builtin 模块
    # 初始化加载 src/extensions/builtin 下的所有 tools.cmake
    # 查找所有 tools.cmake 与 tools-dependency.cmake 模块
    # 基于给定的变量，自动收集所有模块
    # tools.cmake 直接加载
    # tools-dependency.cmake 在构建主程序后加载
include(cmake/builtin.cmake)

spark_file_glob(TOOLS_MODULES
    ${EXTENSTIONS_DIR}/builtin/*/tools.cmake)
spark_file_glob(TOOLS_DEPENDENCY_MODULES
    ${EXTENSTIONS_DIR}/builtin/*/tools-dependency.cmake)

# 加载所有的 tools.cmake
load_builtin_modules(TOOLS_MODULES)

# 将 src 目录中所有 Qt 相关的资源全部收集到变量中
spark_add_executable_path(${PROJECT_NAME}
    src
    src/loader
    src/ui
    src/ui/widgets
    src/utils
    ${BUILTIN_SOURCES} ${WIDGETS_SOURCES} ${TOOLS_MODULES_SOURCES}
    ${QRC_SOURCES}
)
target_link_windowpos(${PROJECT_NAME})
target_compile_definitions(${PROJECT_NAME} PRIVATE ZTBOX_BUILTIN_PLUGINS)

spark_framework_include_with_git(${PROJECT_NAME} 
    https://gitee.com/spark-framework-libs/spark-framework-features
    FEATURES version baseutil screenutil qrcutil
)
spark_framework_include_with_git(${PROJECT_NAME}
    https://gitee.com/zinface/qt.ui-analyzer
    FEATURES ztbox_plugin
)

# 引入 builtin 模块中的定义
    # 加载自动收集的模块依赖 tools-dependency.cmake
load_builtin_modules(TOOLS_DEPENDENCY_MODULES)

# +---------------------------------+
# |      external plugins           |
# +---------------------------------+
add_subdirectory(plugins/external/MimeTypeView)
add_subdirectory(plugins/external/Todo)


# +---------------------------------+
# |          examples               |
# +---------------------------------+
# 构建 examples 示例，也用于测试已安装后的模拟外部构建的示例
option(BUILD_EXAMPLES "模拟外部项目构建示例，如果没有安装此项目时不可用" OFF)
if(BUILD_EXAMPLES)
    add_subdirectory(examples)
endif(BUILD_EXAMPLES)

# 测试示例
add_subdirectory(tests)

# +---------------------------------+
# |      Install Configuration      |
# +---------------------------------+
# 安装目标到 /opt/zTools/bin/ 目录
spark_install_target(/opt/zTools/bin/
    ${PROJECT_NAME})

# 安装文件图标到 /opt/zTools/Components/ToolBox/resources/icon/ 目录
spark_install_file(/opt/zTools/Components/ToolBox/resources/icon/
    assets/spark.png)

# +---------------------------------+
# |    Extensions Configuration     |
# +---------------------------------+
# 安装用于外部项目开发扩展时的参考用例
install(DIRECTORY examples DESTINATION share/${PROJECT_NAME})

# 基于模块进行定义 desktop 文件填充结构
spark_include(cmake/SparkDesktopMacros.cmake)
spark_desktop_macros(
    # 应用名称: Name=
    "${PROJECT_NAME}"
    # 应用名称: Name[zh_CN]=
    "迷你工具箱(z-tools)"
    # 应用说明: Comment=
    "一个简单的迷你工具箱"
    # 应用类型: Type=
    "Application"
    # 执行程序: Exec=
    "/opt/zTools/bin/${PROJECT_NAME}"
    # 图标路径: Icon=
    "/opt/zTools/Components/ToolBox/resources/icon/spark.png"
    # 应用分类: Category=
    "Development"
)

# 使用 cmake 传统语法
# 安装 desktop 文件到 /usr/share/applications 目录
install(FILES ${SPARK_DESKTOP_FILE}
    DESTINATION /usr/share/applications
)

# 项目的依赖图，生成 builddeps 目标
spark_include(SparkBuildGraphviz.cmake)

# +---------------------------------+
# |      Package Configuration      |
# +---------------------------------+
# 注释行(使用方式) - deb 的构建打包操作
spark_include(SparkDebPackageConfig.cmake)
add_package_descript(cmake/spark-deb-package.descript)
